/*
 * A program that communicates with myTestDriver.
 */

#import <driverkit/IODeviceMaster.h>
#import <driverkit/IODevice.h>
#import <mach/mach.h>
#import <libc.h>
#import "myTestDriverUser.h"

void main(void)
{
    IOReturn        ret;
    IOObjectNumber  tag;
    IOString        kind;
    IOCharParameter value;
    unsigned int    count = IO_MAX_PARAMETER_ARRAY_LENGTH, unit = 0;
    char 	    name[80];
    IODeviceMaster *devMaster;
    
    /* Look up the test driver, using IODeviceMaster. */
    devMaster = [IODeviceMaster new];
    sprintf(name, "%s%d", my_DEVICE_NAME, unit);
    ret = [devMaster lookUpByDeviceName:name objectNumber:&tag 
	deviceKind:&kind];
    if (ret != IO_R_SUCCESS) { /* handle the error */
	fprintf(stderr, "Lookup failed: %s\n", 
		[IODevice stringFromReturn:ret]);
	exit(-1);
    } else { /* Successfully got the object number */
    
	/* Get the value of the test driver's parameter. */
	ret = [devMaster getCharValues:value 
		forParameter:my_PARAMETER_NAME objectNumber:tag
		count:&count];
	if (ret != IO_R_SUCCESS) { /* handle the error */
	    fprintf(stderr, "Failed to get parameter value: %s\n", 
		    [IODevice stringFromReturn:ret]);
	    exit(-1);
	} else /* Successfully got the parameter value */
	    printf("Parameter value: %s; count = %d\n", value, count);
    
	/* Just to show we can, get a standard IODevice parameter. */
	count = IO_MAX_PARAMETER_ARRAY_LENGTH;
	ret = [devMaster getCharValues:value 
		forParameter:IO_CLASS_NAME objectNumber:tag
		count:&count];
	if (ret != IO_R_SUCCESS) { /* handle the error */
	    fprintf(stderr, "Failed to get class name: %s\n", 
		    [IODevice stringFromReturn:ret]);
	    exit(-1);
	} else { /* Successfully got the parameter value */
	    printf("Class name: %s; count = %d\n", value, count);
	}
    }
}